﻿import QtQuick 2.2

//2. 利用item进行分组显示其它可视单元,并通过item的children或visibleChildren属性来访问孩子
Rectangle{
    width: 200
    height: 300

    Item{
        id : gradientGroup

        Rectangle{

            x:20
            y:20

            width: 120
            height: 120

            gradient: Gradient{

                GradientStop{ position: 0.0; color: "#202020"}
                GradientStop{ position: 1.0; color: "#A0A0A0"}
            }

        }

        Rectangle {
            x:160
            y:20
            width: 120
            height: 120
            rotation: 90 //旋转90度
            gradient: Gradient{
                GradientStop{ position: 0.0; color:"#202020" }
                GradientStop{ position: 1.0; color: "#A0A0A0"}

            }
        }
    }

    Component.onCompleted: {

        //下面的打印出错
        //gradientGroup.children.length 好像没有这个属性
        console.log("visible children: ",
                    gradientGroup.visibleChildren.left);

        console.log("childrenL ", gradientGroup.children.width);


        console.log("childrenL ", gradientGroup.children.length);

        for(var i=0; i<gradientGroup.children.width; i++){
            console.log("children", i, "x = ", gradientGroup.children[i].x);
        }
    }
}



